<html>
<head><meta charset="utf-8"><title>reordering-diagnostic-children · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/reordering-diagnostic-children.html">reordering-diagnostic-children</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="229967720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/reordering-diagnostic-children/near/229967720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sunjay Varma <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/reordering-diagnostic-children.html#229967720">(Mar 12 2021 at 03:03)</a>:</h4>
<p>I'm trying to add a <code>note</code>  to the diagnostic in the <a href="https://github.com/rust-lang/rust/blob/066f01d81bfbed746f6b6cf27a0426d829e8e832/compiler/rustc_passes/src/dead.rs#L569-L583"><code>warn_dead_code</code> function</a> but having trouble producing the sub-diagnostics in the right order. If I just call <code>lint.build(...).note(...).emit()</code>, the note is emitted after the message about the lint level that gets added in <code>build(...)</code> automatically:</p>
<div class="codehilite"><pre><span></span><code>error: field is never read: `guard`
  --&gt; /home/sunjay/Documents/projects/rust/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs:15:5
   |
LL |     guard: MutexGuard&lt;&#39;a, T&gt;, //~ ERROR field is never read
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard`
   |
note: the lint level is defined here
  --&gt; /home/sunjay/Documents/projects/rust/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs:8:9
   |
LL | #![deny(dead_code)]
   |         ^^^^^^^^^
   = note: &lt;MY NOTE HERE&gt;
</code></pre></div>
<p>Notice the oddly placed <code>&lt;MY NOTE HERE&gt;</code> at the bottom. What I want is this:</p>
<div class="codehilite"><pre><span></span><code>error: field is never read: `guard`
  --&gt; /home/sunjay/Documents/projects/rust/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs:15:5
   |
LL |     guard: MutexGuard&lt;&#39;a, T&gt;, //~ ERROR field is never read
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard`
   |
   = note: &lt;MY NOTE HERE&gt;
note: the lint level is defined here
  --&gt; /home/sunjay/Documents/projects/rust/src/test/ui/lint/dead-code/drop-only-field-issue-81658.rs:8:9
   |
LL | #![deny(dead_code)]
   |         ^^^^^^^^^
</code></pre></div>
<p>Is there a way to achieve that? Right now I have a weird hack that uses the slice <code>reverse()</code> method on the <code>children</code> field of the <code>diagnostic</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>